﻿using System;
using System.Messaging;
using BizUnit;
using BizUnit.BizUnitOM;

namespace BTS.Testing.TraceMonitor.BizUnitSteps
{
    /// <summary>
    /// Starts the event test trace
    /// </summary>
    public class CleanTraceQueue : ITestStepOM
    {
        public string QueuePath { get; set; }
        /// <summary>
        /// Executes the bizunit step
        /// </summary>
        /// <param name="testConfig"></param>
        /// <param name="context"></param>
        public void Execute(System.Xml.XmlNode testConfig, Context context)
        {
            QueuePath = context.ReadConfigAsString(testConfig, "QueuePath");
            Execute(context);
        }

        public void Execute(Context context)
        {
            Execute();
        }

        public void Execute()
        {
            if(!MessageQueue.Exists(QueuePath))
                throw new ApplicationException(string.Format("The queue {0} does not exist", QueuePath));

            var queue = new MessageQueue(QueuePath);
            queue.Purge();
        }

        public void Validate(Context context)
        {

        }
    }
}
